<?php
$title = "主页更改";
include 'header.php';
?>
  <link href="../assets/css/sweetalert2.min.css" rel="stylesheet" type="text/css">

<!--页面主要内容-->
<div class="main-content">
    <div class="page-content">
        <div class="container-fluid">
            <!-- start page title -->
            <div class="row">
                <div class="col-xl-6 offset-xl-3">
                    <div class="card">
                        <div class="card-body">
                            <form class="custom-validation" onsubmit="return false;">
                                <div class="mb-3"><label class="form-label">网站标题：</label>
                                    <input type="text" id="title" class="form-control"  value="<?php echo $home["title"]; ?>" placeholder="请输入你的网站标题">
                                </div>
                                <div class="mb-3"><label class="form-label">网站描述：</label>
                                    <div><input type="text" id="description" class="form-control"  value="<?php echo $home["description"]; ?>" placeholder="请输入网站描述"></div>
                                </div>
                                <div class="mb-3"><label class="form-label">网站关键词：</label>
                                    <div><input type="text" id="keywords" class="form-control"  value="<?php echo $home["keywords"]; ?>" placeholder="请输入网站关键词"></div>
                                </div>
                                <div class="mb-3"><label class="form-label">IP限制：</label>
                                    <div><input type="text" id="ip" class="form-control"  value="<?php echo $home["ip"]; ?>" placeholder="请输入一个ip限制的一天提交举报的次数"></div>
                                </div>
                                <div class="mb-3"><label class="form-label">站长QQ：</label>
                                    <div><input type="text" id="qq" class="form-control"  value="<?php echo $home["qq"]; ?>" placeholder="请输入站长QQ"></div>
                                </div>
                                <div class="mb-3">
                                    <label class="form-label">网站LOGO:</label>
                                    <div>
                                        <div class="bootstrap-filestyle input-group">
                                        <input id="logo" type="text" class="form-control file-value" name="web_site_logo" value="<?php echo $home["logo"]; ?>" placeholder="LOGO图片地址" />
                <input type="file" accaccept=".png,.jpg,.jpeg,.bmp,.gif" hidden/>
                <div class="input-group-btn">
                  <button class="btn btn-success file-browser" type="button">上传图片</button>
                </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="mb-3"><label class="form-label">网站公告</label>
                                <div><textarea id="testtextarea"><?php echo $home["aounce"]; ?></textarea></div>
                                </div>
                                <div class="mb-3"><label class="form-label">免责申明：</label>
                                <div><textarea id="testtextareas"><?php echo $home["shaounce"]; ?></textarea></div>
                                </div>
                                   <div class="mb-3"><label class="form-label">关于本站：</label>
                                <div><textarea id="gybz"><?php echo $home["gybz"]; ?></textarea></div>
                                </div>
                                <div class="mb-3"><label class="form-label">首页底部代码：</label>
                                    <div><textarea  class="form-control" id="footer" rows="5"><?php echo $home["footer"]; ?></textarea></div>
                                    <code>可放入一些统计代码以及备案号</code>
                                </div>
                                  <div class="mb-3"><label class="form-label">百度搜索资源平台Token：</label>
                                    <div><input type="text" id="token" class="form-control"  value="<?php echo $home["token"]; ?>" placeholder="请输入本站百度搜索资源平台Token"></div>
                                    <code>用于提交百度引擎收录，前往<a href="https://ziyuan.baidu.com">百度搜索资源平台</a></code>
                                </div>
                                <div class="text-center">
                                    <div><button type="submit" id="submit" class="btn btn-primary  waves-effect waves-light">更改主页信息
                                        </button></div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div><!-- end col -->
            </div><!-- end row -->
        </div><!-- container-fluid -->
    </div><!-- End Page-content -->
    <footer class="footer">
        <div class="container-fluid">
            <div class="row">
                <div class="col-sm-6">
                    <script>
                        document.write(new Date().getFullYear())
                    </script>(c) Cloud.
                </div>
                <div class="col-sm-6">
                    <div class="text-sm-end d-none d-sm-block">Crafted with <i class="mdi mdi-heart text-danger"></i>By <a href="https://www.9gyun.cn">云风轻产品授权中心</a></div>
                </div>
            </div>
        </div>
    </footer>
</div><!-- end main content-->
<!--End 页面主要内容-->
<?php include("footer.php"); ?>
<script src="../assets/js/sweetalert2.min.js"></script>
  <script src="../assets/tinymce/js/tinymce/tinymce.min.js"></script>
  <script>
  $(document).ready(function(){
    tinymce.init({
    	selector: '#testtextarea',
    	language: 'zh_CN',
    	directionality: 'ltl',
    	browser_spellcheck: true,
    	contextmenu: false,
        height: 480,
    	plugins: [
    		"advlist autolink lists link image charmap print preview anchor",
    		"searchreplace visualblocks code fullscreen",
    		"insertdatetime media table contextmenu paste imagetools wordcount",
    		"code"
    	],
    	toolbar: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image | code",
        images_upload_url: 'set.php?act=uploads', // 后端返回的json格式{ location : "/demo/image/1.jpg" }
    });
    tinymce.init({
    	selector: '#testtextareas',
    	language: 'zh_CN',
    	directionality: 'ltl',
    	browser_spellcheck: true,
    	contextmenu: false,
        height: 480,
    	plugins: [
    		"advlist autolink lists link image charmap print preview anchor",
    		"searchreplace visualblocks code fullscreen",
    		"insertdatetime media table contextmenu paste imagetools wordcount",
    		"code"
    	],
    	toolbar: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image | code",
        images_upload_url: 'set.php?act=uploads', // 后端返回的json格式{ location : "/demo/image/1.jpg" }
    });
      tinymce.init({
    	selector: '#gybz',
    	language: 'zh_CN',
    	directionality: 'ltl',
    	browser_spellcheck: true,
    	contextmenu: false,
        height: 480,
    	plugins: [
    		"advlist autolink lists link image charmap print preview anchor",
    		"searchreplace visualblocks code fullscreen",
    		"insertdatetime media table contextmenu paste imagetools wordcount",
    		"code"
    	],
    	toolbar: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image | code",
        images_upload_url: 'set.php?act=uploads', // 后端返回的json格式{ location : "/demo/image/1.jpg" }
    });
  });
</script>
<script>
    $(document).ready(function() {
    $(document).on('click', '.file-browser', function() {
        var $browser = $(this);
        var file = $browser.closest('.input-group').find('[type="file"]');
        file.on( 'click', function(e) {
            e.stopPropagation();
        });
        file.trigger('click');
    });
    
    $(document).on('change', '.input-group [type="file"]', function() {
        var $this    = $(this);
        var $input   = $(this)[0];
        var $len     = $input.files.length;
        var formFile = new FormData();
        
        if ($len == 0) {
            return false;
        } else {
            var fileAccaccept = $this.attr('accaccept');
            var fileType      = $input.files[0].type;
            var type          = (fileType.substr(fileType.lastIndexOf("/") + 1)).toLowerCase();
            
            if (!type || fileAccaccept.indexOf(type) == -1) {
                alert('您上传图片的类型不符合(.jpg|.jpeg|.gif|.png|.bmp)', 'danger');
                return false;
            }
            formFile.append("file", $input.files[0]);
        }
        
        var data = formFile;
   
        
        $.ajax({
            url: 'set.php?act=upload',
            data: data,
            type: "POST",
            dataType: "json",
            //上传文件无需缓存
            cache: false,
            //用于对data参数进行序列化处理 这里必须false
             processData: false,
            //必须
            contentType: false, 
            success: function (res) {
            
                if (res.status === 1) {
                    $("#logo").val(res.url);
                } else {
                   
                }
            },
        });
    });
});
</script>
<script language="JavaScript">
    $("#submit").click(function() {
        var keywords = $("#keywords").val();
        var title = $("#title").val();
        var description = $("#description").val();
        var footer = $("#footer").val();
        var aounce = tinyMCE.editors[0].getContent()
        var shaounce = tinyMCE.editors[1].getContent()
        var qq = $("#qq").val();
        var logo = $("#logo").val();
        var ip = $("#ip").val();
        var gybz = $("#gybz").val();
        var token = $("#token").val();
        $.ajax({
            type: 'POST',
            url: 'set.php?act=setsys',
            data: {
                title: title,
                keywords: keywords,
                description: description,
                qq: qq,
                ip: ip,
                aounce:aounce,
                shaounce,shaounce,
                footer:footer,
                logo:logo,
                ip:ip,
                gybz:gybz,
                token:token,
                submit: 'submit'
            },
            dataType: 'json',
            success: function(data) {
                if (data.state == 1) {
                    Swal.fire({
                        title: '更新成功!',
                        text: '恭喜你，更新信息成功',
                        icon: 'success',
                        confirmButtonText: 'O了个K!',
                        confirmButtonClass: 'btn btn-success mt-2',
                    });
                } else {
                    Swal.fire({
                        title: '更新失败!',
                        text: '可能信息未做更改',
                        icon: 'error',
                        confirmButtonText: '好!',
                        confirmButtonClass: 'btn btn-info mt-2',
                    });
                }
            }
        });

    });
</script>
</body>

</html>